﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang.OBJECT;

namespace QuanLyBanHang.DAL
{
    public static class DalNhatKyHT
    {
        public static DataTable XemNhatKy()
        {
            return DataHelper.Load(@"select MaNK,Users.TaiKhoan,Ten,TenQuyen,NgayTruyCap from NhatKyHT inner join Users
                                    on NhatKyHT.TaiKhoan = Users.TaiKhoan inner join NhanVien
                                    on Users.MaNV = NhanVien.MaNV inner join Quyen
                                    on Users.MaQuyen = Quyen.MaQuyen");
        }

        public static int Insert(DateTime ngaytruycap,string taikhoan)
        {
            try
            {
                SqlParameter[] para = { new SqlParameter("NgayTruyCap", ngaytruycap), new SqlParameter("TaiKhoan", taikhoan) };
                return DataHelper.Update(para, "spInsertNhatKyHT");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int DeleteAll()
        {
            DataHelper.Open();
            SqlConnection conn = DataHelper.con;
            SqlCommand cmd = new SqlCommand("delete from NhatKyHT", conn);
            try
            {
                int kq = cmd.ExecuteNonQuery();
                return kq;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int Delete(int MaNK)
        {
            try
            {
                SqlParameter[] para = { new SqlParameter("MaNK", MaNK)};
                return DataHelper.Update(para, "spDeleteNhatKyHT");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
